#include "tinyos.h"

task_t task1;
task_t task2;
task_t task3;
task_stack_t task1_stack[1024];
task_stack_t task2_stack[1024];
task_stack_t task3_stack[1024];
int task1_flag;
int task2_flag;
int task3_flag;

void task1_handle(void *param)
{
    system_tick_init(10);
    for (;;) {
        task1_flag = 0;
        //task_delay(1);
        task_supend(cur_task);
        task1_flag = 1;
        //task_delay(1);
        task_supend(cur_task);
    }
}

void task2_handle(void *param)
{
    for (;;) {
        task2_flag = 0;
        task_delay(10);
        task_resume(&task1);
        task2_flag = 1;
        task_delay(10);
        task_resume(&task1);
    }
}

void task3_handle(void *param)
{
    for (;;) {
        task3_flag = 0;
        task_delay(10);
        task3_flag = 1;
        task_delay(10);    
    }
}

void app_init(void)
{
    task_init(&task1, task1_handle,(void *)0x1111, &task1_stack[1024], 
        ARRAY_SIZE(task1_stack), 0);
    task_init(&task2, task2_handle,(void *)0x2222, &task2_stack[1024], 
        ARRAY_SIZE(task2_stack), 1);    
    task_init(&task3, task3_handle,(void *)0x2222, &task3_stack[1024], 
        ARRAY_SIZE(task3_stack), 1);
}

